﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace QBZ.Evaluation.Repositories.Migrations
{
    public partial class oauth : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<Guid>(
                name: "Guid",
                table: "tb_skillChild",
                nullable: false,
                oldClrType: typeof(Guid),
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "Guid",
                table: "tb_skill",
                nullable: false,
                oldClrType: typeof(Guid),
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "Guid",
                table: "tb_evaluation",
                nullable: false,
                oldClrType: typeof(Guid),
                oldNullable: true);

            migrationBuilder.CreateTable(
                name: "tb_oAuth",
                columns: table => new
                {
                    OAuthId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    OpenId = table.Column<string>(maxLength: 100, nullable: false),
                    OAuthWay = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: false),
                    Token = table.Column<string>(maxLength: 100, nullable: false),
                    NickName = table.Column<string>(maxLength: 100, nullable: false),
                    Sex = table.Column<string>(maxLength: 100, nullable: true),
                    Country = table.Column<int>(maxLength: 100, nullable: false),
                    Province = table.Column<string>(maxLength: 100, nullable: true),
                    City = table.Column<string>(maxLength: 100, nullable: true),
                    BirthDay = table.Column<string>(maxLength: 30, nullable: true),
                    FigureUrl = table.Column<string>(maxLength: 500, nullable: true),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_oAuth", x => x.OAuthId);
                    table.ForeignKey(
                        name: "FK_tb_oAuth_tb_user_UserId",
                        column: x => x.UserId,
                        principalTable: "tb_user",
                        principalColumn: "UserId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_tb_evaluation_EvaluationTo",
                table: "tb_evaluation",
                column: "EvaluationTo");

            migrationBuilder.CreateIndex(
                name: "IX_tb_oAuth_UserId",
                table: "tb_oAuth",
                column: "UserId");

            migrationBuilder.AddForeignKey(
                name: "FK_tb_evaluation_tb_user_EvaluationTo",
                table: "tb_evaluation",
                column: "EvaluationTo",
                principalTable: "tb_user",
                principalColumn: "UserId",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_tb_evaluation_tb_user_EvaluationTo",
                table: "tb_evaluation");

            migrationBuilder.DropTable(
                name: "tb_oAuth");

            migrationBuilder.DropIndex(
                name: "IX_tb_evaluation_EvaluationTo",
                table: "tb_evaluation");

            migrationBuilder.AlterColumn<Guid>(
                name: "Guid",
                table: "tb_skillChild",
                nullable: true,
                oldClrType: typeof(Guid));

            migrationBuilder.AlterColumn<Guid>(
                name: "Guid",
                table: "tb_skill",
                nullable: true,
                oldClrType: typeof(Guid));

            migrationBuilder.AlterColumn<Guid>(
                name: "Guid",
                table: "tb_evaluation",
                nullable: true,
                oldClrType: typeof(Guid));
        }
    }
}
